{% extends "base.html" %}

{% block title %}Find and Add Friends - {{ block.super }}{% endblock %}

{% block content %}
    <h2 class="grid_4 suffix_5">Add Friends</h2>
    <div class="grid_9 alpha">
        <form method="GET" class="grid_6">
            <input type="text" name="q" value="{% if q %}{{ q }}{% endif %}" />
            <input type="submit" value="Search" />
        </form>
        <div class="grid_6">
            {% if searched %}
                {% if result %}
                    <p>Hooray, your friend {{ q }} is on the site!</p>
                    {% if request.user.is_authenticated %}
                        {% ifnotequal request.session.username q %}
                            <form method="POST" action="{% url modify_friend %}?next={{ request.path }}{% if q %}&amp;q={{ q }}{% endif %}">
                                <input type="hidden" name="{% if result.friend %}remove{% else %}add{% endif %}-friend" value="{{ q }}" />
                                <input type="submit" value="{% if result.friend %}Remove{% else %}Add{% endif %} Friend" />
                            </form>
                        {% endifnotequal %}
                    {% else %}
                        <a href="{% url login %}?next={{ request.path }}&amp;q={{ q }}">
                            Login to add {{ q }} as a friend
                        </a>
                    {% endif %}
                {% else %}
                    <p>There was nobody with username {{ q }}</p>
                {% endif %}
            {% else %}
                <p>Enter a username above to see if they are on the site!</p>
            {% endif %}
        </div>
    </div>
{% endblock %}
